//
//  PzMeCtrl.swift
//  Pz
//
//  Created by 蓝鳍互娱 on 2024/6/28.
//

import UIKit
import SwifterSwift
class PzMeCtrl: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .clear
        creatSubView()
    }
    lazy var meBgImgView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "pzMeBg")
        return imageView
    }()
    lazy var meNavBackBtn: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: #selector(meNavBack), for: .touchUpInside)
        btn.setBackgroundImage(UIImage(named: "pzNavBackIcon"), for: .normal)
        return btn
    }()
    lazy var meNavTitleLab: UILabel = {
        let lab = UILabel()
        lab.text = "我的"
        lab.font = UIFont.systemFont(ofSize: 34.fitScale(), weight: .regular)
        lab.textColor = UIColor(hex:0xFFFFFF)
        return lab
    }()
    lazy var meHeadView: PzMeHeadView = {
        let lab = PzMeHeadView()
        lab.isHidden = true
        return lab
    }()
    lazy var meUserAgreementView: PzMeAgreementView = {
        let lab = PzMeAgreementView()
        lab.agreementType = "1"
        return lab
    }()
    lazy var mePriveAgreementView: PzMeAgreementView = {
        let lab = PzMeAgreementView()
        lab.agreementType = "2"
        return lab
    }()
    
    func creatSubView(){
        self.view.addSubview(meBgImgView)
        self.view.addSubview(meNavTitleLab)
        self.view.addSubview(meNavBackBtn)
        self.view.addSubview(meHeadView)
        self.view.addSubview(meUserAgreementView)
        self.view.addSubview(mePriveAgreementView)
        
        meBgImgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        meNavBackBtn.snp.makeConstraints { make in
            make.left.equalTo(24.fitScale())
            make.top.equalTo(PzPublicConst.ScreenTopSpaceHeight + 12.fitScale())
            make.width.height.equalTo(64.fitScale())
        }
        meNavTitleLab.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(meNavBackBtn)
            make.height.equalTo(50.fitScale())
        }
        meHeadView.snp.makeConstraints { make in
            make.top.equalTo(PzPublicConst.ScreenTopSpaceHeight + 108.fitScale())
            make.centerX.equalToSuperview()
            make.width.equalTo(702.fitScale())
            make.height.equalTo(0.fitScale())
        }
        meHeadView.openVipBlock = {
            let vipCtrl = PzVipCtrl()
            let vipNavCtrl = UINavigationController(rootViewController: vipCtrl)
            vipNavCtrl.isNavigationBarHidden = true;
            vipNavCtrl.modalPresentationStyle = .fullScreen;
            self.present(vipNavCtrl, animated: true) {
                
            }
            vipCtrl.applePayScuessBlock = {
                self.meHeadView.updataVipStatus()
            }
        }
        
        meUserAgreementView.snp.makeConstraints { make in
            make.top.equalTo(meHeadView.snp.bottom).offset(19.fitScale())
            make.left.equalTo(0.fitScale())
            make.right.equalTo(-0.fitScale())
            make.height.equalTo(104.fitScale())
        }
        meUserAgreementView.checkUserAgreementBlock = {
            let webCtrl = PzWebCtrl()
            webCtrl.webUrl = PzPublicConst.photoUserAgreementUrl
            self.navigationController?.pushViewController(webCtrl, animated: true)
        }
        
        mePriveAgreementView.snp.makeConstraints { make in
            make.top.equalTo(meUserAgreementView.snp.bottom)
            make.left.equalTo(0.fitScale())
            make.right.equalTo(-0.fitScale())
            make.height.equalTo(104.fitScale())
        }
        mePriveAgreementView.checkPriveAgreementBlock = {
            let webCtrl = PzWebCtrl()
            webCtrl.webUrl = PzPublicConst.photoPriveAgreementUrl
            self.navigationController?.pushViewController(webCtrl, animated: true)
        }
    }
    @objc func meNavBack(){
        self.navigationController?.popViewController(animated: true)
    }
}
